<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%   
          java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm"); 
          java.util.Date currentTime = new java.util.Date();//得到当前系统时间 
          String str_date = formatter.format(currentTime); //将日期时间格式化 
 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>main</title>
<jsp:include page="../head.jsp" />
<link rel="stylesheet" type="text/css" media="screen" href="<%=path %>/js/jquery.combogrid/resources/css/smoothness/jquery-ui-1.10.1.custom.css"/>
<script type="text/javascript" src="<%=path %>/js/jquery.combogrid/resources/jquery/jquery-ui-1.10.1.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="<%=path %>/js/dropdown-check-list/src/ui.dropdownchecklist.themeroller.css" />
<script type="text/javascript" src="<%=path %>/js/dropdown-check-list/src/ui.dropdownchecklist.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="<%=path %>/js/jquery.combogrid/resources/css/smoothness/jquery.ui.combogrid.css"/>
<script type="text/javascript" src="<%=path %>/js/jquery.combogrid/resources/plugin/jquery.ui.combogrid-1.6.3.js"></script>
<script type="text/javascript">

	function save(){
		if(trim($("#loginName").val())==""){
			addError("loginName","用户名称不能为空.");
			return;
		}else if(trim($("#realName").val())==""){
			addError("realName","真实姓名不能为空.");
			return;
		}else if(trim($("#loginPwd").val())==""){
			addError("loginPwd","用户密码不能为空.");
			return;
		}else if(trim($("#confirmPwd").val())==""){
			addError("confirmPwd","确认密码不能为空.");
			return;
		}else if(trim($("#identityCard").val())==""){
			addError("identityCard","身份证号不能为空.");
			return;
		}else if(!IdCardValidate($("#identityCard").val())){
			addError("identityCard","身份证号不符合规则.");
			return;
		}else if($("#roleIds").val()==null){
			addError("ddcl-roleIds","请为用户分配角色");
			return;
		}else if(trim($("#areaId").val())==""){
			addError("areaName","用户区域不能为空.");
			return;
		}else if(inputNum($("#userAge").val())==null){
			addError("userAge","只允许输入数字.");
			return;
		}else if(inputNum($("#userQq").val())==null){
			addError("userQq","只允许输入数字.");
			return;
		}else{
			if (!checkForm(document.getElementById("saveForm"))) {
				return;
			}else{
				xbox.load("loading");
				$.ajax({
					url			:"<%=path%>/user/userAjax_verifyUser_successFlagAction.action",
					type 		: "POST",
					dataType 	: "json",
					data		: {
						"loginName":trim($("#loginName").val()),
						"userId":0
						
					},
					success 	: function(data) {
						if(data==1){
							$("#saveForm").ajaxSubmit(function(){
								$("#refreshForm").submit();
						    });
						}else{
							addError("loginName","用户名已存在.");
						}
					},
					error		:function(){
						xbox.alert("数据正在提交，请稍候，或检查您的网络环境,确保其连接正常！");
					}
				});
			}
		}

	}
	
	function roleChange(obj){
		$.ajax({
				url			:"<%=path%>/role/roleAjax_queryRoleListByRoleIds_listAction.action?roleIds="+$(obj).val(),
				type 		: "POST",
				dataType 	: "json",
				data		: {
				},
				success 	: function(data) {
					var str="";
					for(var i=0;i<data.length;i++){
						str+='<option value="'+data[i].roleId+'">'+data[i].roleName+'</option>';
					}
					$("#mainRoleId").html(str);
				},
				error		:function(){
					xbox.alert("数据正在提交，请稍候，或检查您的网络环境,确保其连接正常！");
				}
			});
	}
	function turnBack(){
		$("#refreshForm").submit();
	}
	$(function(){
		$("#roleIds").dropdownchecklist( { emptyText: "请选择角色", maxDropHeight: 150, width: 240 } );
	});
</script>
</head>
<body>
<form action="<%=path%>/user/user_save_listAction.action" method="post" id="saveForm">
<table width="98%" align="center" border="0" cellpadding="4" cellspacing="1" bgcolor="#F1F1F1" style="margin-bottom:8px">
  <tr bgcolor="#FFFFFF">
    <td colspan="4" height="16"><span></span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF"><span style="color:red;">*</span>用户名称：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
              <input maxlength="25" type="text" name="user.loginName" id="loginName" value="${user.loginName}" />
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF"><span style="color:red;">*</span>真实姓名：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
              <input maxlength="25" type="text" name="user.realName" id="realName" value="${user.realName}" />
    </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF"><span style="color:red;">*</span>用户密码：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
              <input maxlength="25" type="password" name="user.loginPwd" id="loginPwd" value="123456" />
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF"><span style="color:red;">*</span>确认密码：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
              <input maxlength="25" type="password" name="confirmPwd" id="confirmPwd" value="123456" />
    </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF"><span style="color:red;">*</span>身份证：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
               <input maxlength="25" type="text" name="user.identityCard" id="identityCard" value="${user.identityCard}" />
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">性别：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF"><input name="user.userSex" id="userSexYes" type="radio" value="1" checked="checked"/>男&nbsp;<input name="user.userSex" id="userSexNo" type="radio" value="0"/>女</td>
  </tr>
  <tr bgcolor="#FFFFFF">
  		<td width="10%" align="right" bgcolor="#FFFFFF">所属公司：</td>
	    <td width="40%" align="left" bgcolor="#FFFFFF">
	    <c:if test="${sessionUser.userId eq 1}">
	    	<select id="parentCompanyId" name="companyId">
		    	<option value="1">默认设置</option>
		    	<c:forEach items="${companyList}" var="com">
		    	<option value="${com.companyId}"><c:out value="${com.companyName}" /></option>
		    	</c:forEach>
		   	</select>
	    </c:if>
	    <c:if test="${sessionUser.userId ne 1}">
	     	<input type="hidden" value="${sessionUser.company.companyId}"/>${sessionUser.company.companyName}
	    </c:if>
		   	
	    </td>
	   	<td width="10%" align="right" bgcolor="#FFFFFF">所属部门：</td>
	    <td width="40%" align="left" bgcolor="#FFFFFF">
	    <select name="departmentId" id="departmentId" >
	          	<c:forEach items="${departmentList}" var="dep">
	          		<option value="${dep.departmentId}" <c:if test="${dep.defaultFlag eq 1 }">selected="selected"</c:if>>${dep.departmentName}</option>
	          	</c:forEach>
	          	</select>
	    </td>
    </tr>
   <tr bgcolor="#FFFFFF">
   	<td width="10%" align="right" bgcolor="#FFFFFF">所属职位：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
    <select name="positionId" id="positionId" >
          	<c:forEach items="${positionList}" var="obj">
          		<option value="${obj.positionId}" <c:if test="${obj.defaultFlag eq 1 }">selected="selected"</c:if>>${obj.positionName}</option>
          	</c:forEach>
          	</select>
    </td>
   	<td width="10%" align="right" bgcolor="#FFFFFF">在职状态：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
    <select name="user.positionState" id="positionState" >
          	<option value="1">试用</option>
          	<option value="2">正式</option>
          	<option value="3">离职</option>
          	<option value="4">其它</option>
          </select>
    </td>
    </tr>
    
    
    <tr bgcolor="#FFFFFF" style="display: none;">
    <td width="10%" align="right" bgcolor="#FFFFFF">昵称：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
               <input maxlength="25" type="text" name="user.userNickname" id="userNickname" value="${user.userNickname}" />
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">年龄：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
               <input maxlength="25" type="text" name="user.userAge" id="userAge" value="${user.userAge}" />
    </td>
  </tr>
  <tr bgcolor="#FFFFFF" style="display: none;">
    <td width="10%" align="right" bgcolor="#FFFFFF">Email：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
              <input maxlength="25" type="text" name="user.userEmail" id="userEmail" value="${user.userEmail}" />
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">QQ：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
              <input maxlength="25" type="text" name="user.userQq" id="userQq" value="${user.userQq}" />
    </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF">生日：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
    	<input maxlength="25" type="text" name="user.userBirthday" id="userBirthday" value="${user.userBirthday}" onfocus="WdatePicker({startDate:'%y-%M-%d',minDate:'1949-10-01',maxDate:'2020-10-01'});"/>
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">电话：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
               <input maxlength="25" type="text" name="user.userPhone" id="userPhone" value="${user.userPhone}" />
    </td>
  </tr>
  
  <tr bgcolor="#FFFFFF" style="display: none;">
     <td width="10%" align="right" bgcolor="#FFFFFF">地址：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
               <input maxlength="25" type="text" name="user.userAddress" id="userAddress" value="${user.userAddress}" />
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">用户初始状态</td>
    <td width="40%" align="left" bgcolor="#FFFFFF"><input name="user.userState" id="userStateYes" type="radio" value="1" checked="checked"/>启用&nbsp;<input name="user.userState" id="userStateNo" type="radio" value="0" <c:if test="${user.userState eq 0}">checked="checked"</c:if>/>禁用</td>
  </tr>
  
 <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF">分配角色：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
    
            
               <select id="roleIds" name="roleIds" class="roleIds" <c:if test="${sessionScope.systemInfo.moreRole eq 1 }">multiple="multiple"</c:if> onchange="roleChange(this)">
    			<c:forEach items="${roleList}" var="role">
    				<option value="${role.roleId}">${role.roleName}</option>
    			</c:forEach>
    		</select>
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">主要角色：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
            <select id="mainRoleId" name="mainRoleId" class="mainRoleId">
            	<option value="0">请先分配角色</option>
    		</select>
    </td>
    </tr>
  <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF">备注：</td>
    <td width="90%" colspan="3" align="left" bgcolor="#FFFFFF">
            	<textarea rows="3"  name="user.remark" id="remark">${user.remark}</textarea>
    </td>
  </tr>
  <tr align="right" bgcolor="#F1F1F1">
	<td height="36" colspan="4" align="center">
		<input type='button' class="btn btn-primary" id="btnSave" onclick="save();" value='保存' />
	    &nbsp;<input type='button' class="btn" onclick="turnBack();" value='返回' />
</td>
</tr>
</table>
</form>

<form action="${listUrl}" method="post" style="display: none;" id="refreshForm" name="refreshForm"/>
	

</body>
</html>
